import type { BasicColumn, FormSchema } from '@/components/Table'
import { useRender } from '@/components/Table'
import { DICT_TYPE, getDictOptions } from '@/utils/dict'
import { useUserStore } from '@/store/modules/user'
import { ycListSimple } from '@/api/wages/salaryslip'

const userStore = useUserStore()
const ycListSimpleRes = await ycListSimple()

export const columns: BasicColumn[] = [
  {
    title: '类型',
    dataIndex: 'type',
    width: 180,
    customRender: ({ text }) => {
      return useRender.renderDict(text, DICT_TYPE.ASSESSMENT_CONFIG)
    },
  },
  {
    title: '名称',
    dataIndex: 'name',
    width: 160,
  },
  {
    title: '所属部门',
    dataIndex: 'deptName',
    width: 180,
    ifShow: () => userStore.getUserInfo.roles.some(item => item === 'city_admin' || item === 'super_admin' || item === 'wages_admin'),
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: 180,
    customRender: ({ text }) => {
      return useRender.renderDate(text)
    },
  },
]

export const searchFormSchema: FormSchema[] = [
  {
    label: '类型',
    field: 'type',
    component: 'Select',
    componentProps: {
      options: getDictOptions(DICT_TYPE.ASSESSMENT_CONFIG, 'string'),
    },
    colProps: { span: 8 },
  },
  {
    label: '名称',
    field: 'name',
    component: 'Input',
    colProps: { span: 8 },
  },
  {
    label: '所属部门',
    field: 'deptId',
    component: 'Select',
    ifShow: () => userStore.getUserInfo.roles.some(item => item === 'city_admin' || item === 'super_admin' || item === 'wages_admin'),
    componentProps: {
      options: ycListSimpleRes,
      fieldNames: {
        label: 'name',
        value: 'id',
      },
    },
    colProps: { span: 8 },
  },
  {
    label: '创建时间',
    field: 'createTime',
    component: 'RangePicker',
    colProps: { span: 8 },
  },
]

export const createFormSchema: FormSchema[] = [
  {
    label: '编号',
    field: 'id',
    show: false,
    component: 'Input',
  },
  {
    label: '类型',
    field: 'type',
    required: true,
    component: 'Select',
    componentProps: {
      options: getDictOptions(DICT_TYPE.ASSESSMENT_CONFIG, 'string'),
    },
  },
  {
    label: '名称',
    field: 'name',
    required: true,
    component: 'Input',
  },
  {
    label: '描述',
    field: 'describe',
    required: true,
    component: 'Input',
  },
  {
    label: '所属部门',
    field: 'deptId',
    required: true,
    component: 'Select',
    ifShow: () => userStore.getUserInfo.roles.some(item => item === 'city_admin' || item === 'super_admin' || item === 'wages_admin'),
    componentProps: {
      options: ycListSimpleRes,
      fieldNames: {
        label: 'name',
        value: 'id',
      },
    },
  },
]

export const updateFormSchema: FormSchema[] = [
  {
    label: '编号',
    field: 'id',
    show: false,
    component: 'Input',
  },
  {
    label: '类型',
    field: 'type',
    required: true,
    component: 'Select',
    componentProps: {
      options: getDictOptions(DICT_TYPE.ASSESSMENT_CONFIG, 'string'),
    },
  },
  {
    label: '名称',
    field: 'name',
    required: true,
    component: 'Input',
  },
  {
    label: '描述',
    field: 'describe',
    required: true,
    component: 'Input',
  },
  {
    label: '所属部门',
    field: 'deptId',
    required: true,
    ifShow: () => userStore.getUserInfo.roles.some(item => item === 'city_admin' || item === 'super_admin' || item === 'wages_admin'),
    component: 'Select',
    componentProps: {
      options: ycListSimpleRes,
      fieldNames: {
        label: 'name',
        value: 'id',
      },
    },
  },
]
